﻿using ASPNETVN.PORTAL.Components.UI;
using System;
using CrystalDecisions.CrystalReports.Engine;
using CUSTOMS.Modules.QLHS.Components.QLBB;
using System.Data;
using System.Web.UI.WebControls;
using System.Collections.Specialized;
using System.Collections;
using CUSTOMS.Components;
using System.Web.UI;
using ASPNETVN.PORTAL.Components.Helpers;

namespace CUSTOMS.Modules.QLHS.Controls
{
    public partial class InBienBan : ModulePage
    {
        protected void Page_Load(object sender, EventArgs e)
        {
            if (IsPostBack == false)
            {
                txtMaLoaiHinh.Text = Request.QueryString["maloaihinh"];
                txtmaHaiQuan.Text = Request.QueryString["mahaiquan"];
                txtSoToKhai.Text = Request.QueryString["sotokhai"];
                txtHaiQuan.Text = DanhMuc.GetTenDonViHaiQuan(Request.QueryString["mahaiquan"]);
                txtLoaiHinh.Text = DanhMuc.GetTenLoaiHinhMauDich(Request.QueryString["maloaihinh"]);
                txtNamDangKy.Text = Request.QueryString["namdangky"];
            }
        }

        protected void btnInBienBan_Click(object sender, EventArgs e)
        {
            int sotokhai = Convert.ToInt32(Request.QueryString["sotokhai"]);
            string mahaiquan = Request.QueryString["mahaiquan"];
            string maloaihinh = Request.QueryString["maloaihinh"];
            int namdangky = Convert.ToInt32(Request.QueryString["namdangky"]);

            Hashtable settings = this.ParentControl.Settings;
            // Report.
            ReportDocument rpt = new ReportDocument();
            string path = Server.MapPath("~/Modules/CUSTOMS.Modules.QLHS/Reports/BienBanBanGiao.rpt");
            rpt.Load(path);

            BienBan bienban = BienBan.Load(sotokhai, mahaiquan, maloaihinh, namdangky);

            DataSet dsHangHoa = HangHoa.SelectBy_ToKhai(sotokhai, mahaiquan, maloaihinh, namdangky);

            rpt.SetDataSource(dsHangHoa.Tables[0]);

            rpt.SetParameterValue("CucHaiQuan", settings["CucHaiQuan"].ToString());
            rpt.SetParameterValue("HaiQuanCaiDat", settings["TenHaiQuan"].ToString());
            rpt.SetParameterValue("SoBienBan", bienban.SoBienBan);
            rpt.SetParameterValue("NgayBanGiao", bienban.NgayBanGiao);
            rpt.SetParameterValue("NoiGiao", DanhMuc.GetTenDonViHaiQuan(bienban.NoiGiao));
            rpt.SetParameterValue("NoiNhan", DanhMuc.GetTenDoanhNghiep(bienban.NoiNhan));
            rpt.SetParameterValue("NguoiNhan", bienban.NguoiNhan);
            rpt.SetParameterValue("SoVanTaiDon", bienban.SoVanTaiDon);
            rpt.SetParameterValue("SoBanChinhToKhai", bienban.SoBanChinhToKhai);
            rpt.SetParameterValue("SoBanChinhDonChuyenCuaKhau", bienban.SoBanChinhDonChuyenCuaKhau);
            rpt.SetParameterValue("SoBanSaoVanTaiDon", bienban.SoBanSaoVanTaiDon);
            rpt.SetParameterValue("SoBanChinhBanKeChiTiet", bienban.SoBanChinhBanKeChiTiet);
            rpt.SetParameterValue("TuyenDuongVanChuyen", bienban.TuyenDuongVanChuyen);
            rpt.SetParameterValue("ChieuDai", bienban.ChieuDai);
            rpt.SetParameterValue("ThoiGianVanChuyen", bienban.ThoiGianVanChuyen);
            rpt.SetParameterValue("GioXuatPhat", bienban.GioXuatPhat);
            rpt.SetParameterValue("HaiQuanChuyenDen", DanhMuc.GetTenDonViHaiQuan(bienban.MaHaiQuanChuyenDen));
            rpt.SetParameterValue("BienBanVeTinhTrangHangHoa", bienban.BienBanVeTinhTrangHangHoa);
            rpt.SetParameterValue("TinhTrangHangHoa", bienban.TinhTrangHangHoa);
            rpt.SetParameterValue("CacVanDeLienQuan", bienban.CacVanDeLienQuan);

            Session["CUSTOMS.Modules.QLHS.Report"] = rpt;
            Response.Redirect(string.Format("~/Modules/CUSTOMS.Modules.QLHS/ViewReport.aspx?tabid={0}&mid={1}", this.TabID, this.ModuleID));
       
        }

        protected void btnClose_Click(object sender, EventArgs e)
        {
            string url = HttpUrlBuilder.BuildModulePageUrl(this.ModuleID, 0, ModulePages.TheoDoiBienBan);
            Response.Redirect(url);
        }
    }
}